package com.longrise.android.byjk.utils;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.Reader;
import java.lang.reflect.Type;

/**
 * Created by sujizhong on 2017/1/5.
 */

public class JsonUtil {

    private static Gson GSON;

    static {
        GSON = new GsonBuilder().serializeNulls().disableHtmlEscaping().excludeFieldsWithoutExposeAnnotation().create();
    }

    public static Gson getGson() {
        return GSON;
    }

    public static String toJson(Object json) {
        return GSON.toJson(json);
    }

    public static <T> T fromJson(String jsonStr, Type type) {
        return GSON.fromJson(jsonStr, type);
    }

    public static <T> T fromJson(Reader reader, Type type) {
        return GSON.fromJson(reader, type);
    }
}
